<!--
 * @Description: In User Settings Edit
 * @Author: your name
 * @Date: 2019-09-25 18:27:11
 * @LastEditTime: 2019-11-09 14:19:28
 * @LastEditors: Please set LastEditors
 -->
<template>
  <div class="container">
    <div class="container_card">
      <div class="container_head">
        <svg-icon icon-class="list" />  打包历史
      </div>
      <div class="container_body">
        <template>
          <el-table
            v-loading="loading"
            :data="tableData"
            style="width: 100%"
          >
            <el-table-column
              prop="id"
              label="ID"
            />
            <el-table-column
              prop="game_name"
              label="游戏名称"
            />
            <el-table-column
              prop="version"
              label="游戏版本"
            />
            <el-table-column
              prop="alias"
              label="渠道名称"
            />
            <el-table-column
              prop="channel_version"
              label="渠道版本"
            />
            <el-table-column
              prop="sign_name"
              label="签名"
            />
            <el-table-column
              prop="system"
              label="平台"
            />
            <el-table-column
              prop="created_at"
              label="开始时间"
            />
            <el-table-column
              prop="state"
              label="状态"
            >
              <template slot-scope="scope">
                <div v-if="scope.row.state ===0">打包中</div>
                <div v-if="scope.row.state ===1">打包完成</div>
                <div v-if="scope.row.state ===2">打包失败</div>
              </template>
            </el-table-column>
            <el-table-column
              fixed="right"
              label="操作"
              width="180"
            >
              <template slot-scope="scope">
                <el-button type="text" size="small" @click="download_apk(scope.row)">下载包</el-button>
                <el-button type="text" size="small" @click="look_log(scope.row)">查看日志</el-button>
              </template>
            </el-table-column>
          </el-table>
          <div class="pagination_list">
            <el-pagination
              v-if="total*pageSize > 8"
              background
              layout="prev, pager, next"
              :total="total"
              :page-size="pageSize"
              @current-change="page_channel"
            />
          </div>

        </template>

      </div>
    </div>
  </div>
</template>

<script>
import config from '../../config/config'
export default {
  data() {
    return {
      tableData: [],
      download_url: config.BASE_URL,
      pageSize: 8,
      page: '1',
      total: 0,
      loading: true
    }
  },
  mounted() {
    this.get_page_list()
  },
  methods: {
    download_apk(res) {
      // 把excel发送出来
      var url = this.download_url + 'download_apk?id=' + res.id + '&game_name=' + res.game_name
      window.open(url)
      // this.$api.download_apk(data).then(res => {

      // })
    },
    look_log(res) {

    },
    page_channel(e) {
      console.log(e)
      this.page = e
      this.get_page_list()
    },
    get_page_list() {
      const data = {
        'page': this.page,
        'size': this.pageSize
      }
      this.$api.get_tasks(data).then(res => {
        console.log(res)
        this.total = res.total
        this.tableData = res.data
        this.loading = false
      })
    }
  }
}
</script>

<style scoped>
.pagination_list{
  margin-top: 20px
}
</style>
